//
//  FBHomeVideoListTableViewCell.m
//  MusicForChilden
//
//  Created by qlydfb on 2021/10/28.
//

#import "FBHomeVideoListTableViewCell.h"

@interface FBHomeVideoListTableViewCell()
@property(strong, nonatomic)UIImageView *showImg;
@property(strong, nonatomic)UILabel *nameLbl;
@property(strong, nonatomic)UILabel *teacherNameLbl;
//@property(strong, nonatomic)UILabel *
@end
@implementation FBHomeVideoListTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
  
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        [self initView];
    }
    return self;
}
- (void)initView{
    self.backgroundColor = [UIColor clearColor];
    self.contentView.backgroundColor = [UIColor whiteColor];
    self.showImg = [[UIImageView alloc]init];
    self.showImg.contentMode = UIViewContentModeScaleAspectFit;
    [self.contentView addSubview:self.showImg];
    [self.showImg mas_makeConstraints:^(MASConstraintMaker *make) {
       make.left.mas_equalTo(15) ;
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(50, 50));
    }];
    self.nameLbl = [[UILabel alloc]init];
    self.nameLbl.backgroundColor = [UIColor clearColor];
    self.nameLbl.font = [UIFont boldSystemFontOfSize:18];
    self.nameLbl.textColor = [UIColor blackColor];
    self.nameLbl.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:self.nameLbl];
    [self.nameLbl mas_makeConstraints:^(MASConstraintMaker *make) {
       make.left.mas_equalTo(self.showImg.mas_right).offset(8) ;
        make.top.mas_equalTo(self.showImg.mas_top);
    }];
    self.teacherNameLbl = [[UILabel alloc]init];
    self.teacherNameLbl.backgroundColor = [UIColor clearColor];
    self.teacherNameLbl.font = [UIFont systemFontOfSize:14];
    self.teacherNameLbl.textAlignment = NSTextAlignmentLeft;
    self.teacherNameLbl.textColor = [UIColor colorWithWhite:0 alpha:0.6];
    [self.contentView addSubview:self.teacherNameLbl];
    [self.teacherNameLbl mas_makeConstraints:^(MASConstraintMaker *make) {
       make.left.mas_equalTo(self.nameLbl.mas_left)     ;
        make.top.mas_equalTo(self.nameLbl.mas_bottom).offset(10);
    }];
}
- (void)showCellModel:(FBVideoListDetailMode *)model{
    [self.showImg sd_setImageWithURL:[NSURL URLWithString:model.cover] placeholderImage:[UIImage imageNamed:@"default"]];
    self.nameLbl.text = model.title;
    self.teacherNameLbl.text = [NSString stringWithFormat:@"时长:%@ ",[self getMMSSFromSS:model.duration]];
}
-(NSString *)getMMSSFromSS:(NSString *)totalTime{

    NSInteger seconds = [totalTime integerValue];

    //format of hour

    NSString *str_hour = [NSString stringWithFormat:@"%02ld",seconds/3600];

    //format of minute

    NSString *str_minute = [NSString stringWithFormat:@"%02ld",(seconds%3600)/60];

    //format of second

    NSString *str_second = [NSString stringWithFormat:@"%02ld",seconds%60];

    //format of time

    NSString *format_time = [NSString stringWithFormat:@"%@:%@:%@",str_hour,str_minute,str_second];

    return format_time;

}
@end
